﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace Zombie_Demo.Utilities
{
    public class KeysState
    {
        #region variables
        private bool pressed;
        private bool wasPressed;
        private TimeSpan durrationOfPress;
        private DateTime timeofPress;
        private Keys key;
        #endregion

        #region Retrievers
        /// <summary>
        /// Returns if the key is being pressed.
        /// </summary>
        internal bool Pressed { get { return this.pressed; } set { this.pressed = value; } }

        /// <summary>
        /// Returns if the key was pressed last frame
        /// </summary>
        internal bool WasPressed { get { return this.wasPressed; } set { this.wasPressed = value; } }

        /// <summary>
        /// Returns the time durration of the last key press
        /// </summary>
        internal TimeSpan LengthOfPress { get { if (pressed) { return DateTime.Now - timeofPress; } else { return durrationOfPress; } } set { this.durrationOfPress = value; } }

        /// <summary>
        /// Returns the durration of the current keypress, returns the current time if the key is not being pressed
        /// </summary>
        internal DateTime PressedTime { get { return this.timeofPress; } set { this.timeofPress = value; } }

        /// <summary>
        /// Returns the key that this KeysState represents
        /// </summary>
        public Keys Key { get { return this.key; } }
        #endregion

        #region Constructors
        public KeysState()
        {
            pressed = false;
            wasPressed = false;
        }

        /// <summary>
        /// Build a new KeysState
        /// </summary>
        /// <param name="k">The key that is desired</param>
        public KeysState(Keys k)
        {
            pressed = false;
            durrationOfPress = new TimeSpan(0, 0, 0);
            key = k;
        }

        /// <summary>
        /// Build a new KeysState
        /// </summary>
        /// <param name="k">They key in question</param>
        /// <param name="timeOfLastPress">The time when the key was pressed</param>
        /// <param name="pressed">Is the key currently pressed</param>
        /// <param name="wasPressed">Was the key pressed in the previous frame</param>
        public KeysState(Keys k, DateTime timeOfLastPress, bool pressed, bool wasPressed)
        {
            this.key = k;
            this.timeofPress = timeOfLastPress;
            this.pressed = pressed;
            this.wasPressed = wasPressed;
        }
        #endregion

        /// <summary>
        /// Update the KeysState, probably better to just make a new one
        /// </summary>
        public void Update()
        {
            KeysState keyState = KeyboardWrapper.GetKeyState(key);
        }

        public bool FirstPress()
        {
            return (pressed && !wasPressed);
        }
    }
}
